<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<html>

<head>
    <style>
        body {
            background: url("/img/bg.jpg");
            width: 100%;
        }
    </style>
    <title>编辑游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/editTravels.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/eleditor/Eleditor.min.js"></script>
    <script src="/js/plugins/eleditor/webuploader.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script src="/js/My97DatePicker/WdatePicker.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {
            //回显全部的地区
            $.get("/regions", function (data) {
                var temp = "";
                $.each(data, function (index, ele) {
                    temp += " <option value='" + ele.id + "'>" + ele.name + "</option>";
                })
                $("#regionSelect").html(temp);
                /*     var params = getParams();
                     console.log(params);
                     if (params.id) {
                         $("#detailForm").attr('action', "/travels");
                         $("input[name='_method']").val("put");

                         $.get("/travels/" + params.id, function (data) {
                             $(".travels").renderValues(data);
                         });
                     }*/
            });

            var Edr = new Eleditor({
                el: '#contentEditor',
                upload: {
                    server: '/images',
                },
            });

            //给设置封面的按钮绑定点击事件
            $("#changeBtn").click(function () {
                $("#file").click();
            });
            $("#file").change(function () {
                if ($(this).val()) {
                    $("#fileForm").ajaxSubmit(function (data) {
                        if (data.status) {
                            $("#coverUrl").attr("src", data.url);
                        }
                    });
                }
            });

            //日历插件
            $("#detailForm input[name='travelTime']").click(function () {
                WdatePicker();
            });

            //将表单转化为ajax表单,通过点击保存和发布按钮来提交表单
            $("#detailForm").ajaxForm({
                // url: "/togethers",
                success: function (data) {
                    if (data.success) {
                        window.location.href = "/together.html";
                    }
                },
                beforeSubmit: function (arr) {
                    arr.push({name: "title", value: $("#title").val()});
                    arr.push({name: "coverUrl", value: $("#coverUrl").attr("src")});
                    arr.push({name: "content.content", value: Edr.getContent()});
                }
            });
            $("#releaseBtn").click(function () {
                console.log($("#detailForm input[name='travelTime']").val());
                $("#detailForm").submit();
            })
        })
    </script>


</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:window.history.go(-1);">
                <span><i class="fa fa-times"></i></span>
            </a>
        </div>
        <div class="col-5"></div>
        <div class="col" style="text-align: right;">
            <i class="fa fa-floppy-o fg-fw" id="saveBtn"><span>保存</span></i>
            <i class="fa fa-check" id="releaseBtn"><span>发布</span></i>
        </div>
    </div>
</div>
<form id="fileForm" method="post" action="/images">
    <!--隐藏的文件上传控件-->
    <input type="file" id="file" name="file" style="display: none" formenctype="multipart/form-data"/>
</form>
<div class="travels form-group">
    <div class="cover">
        <img id="coverUrl" width="100%" height="200px" render-src="coverUrl"/>

        <button type="button" class="btn" id="changeBtn">
            <i class="fa fa-pencil-square-o"></i>
            <small>更换封面</small>
        </button>
    </div>

    <div class="title">
        <input class="form-control" id="title" placeholder="请输入标题" render-value="title"/>
    </div>
    <h6 href="#">点击文章内容即可编辑</h6>
    <div id="contentEditor" name="content.content" render-html="togetherContent.content">
    </div>
    <hr/>
    <div class="container">
        <form id="detailForm" method="post" action="/togethers">
            <input type="hidden" name="id" render-value="id"/>
            <!--<input type="hidden" name="_method"/>-->
            <label>出行时间:</label>
            <input type="text" name="travelTime" class="form-control">
            <label>出行天数:</label>
            <input type="number" name="days" class="form-control" render-value="days">
            <!--<label>出行人数:</label>
            <input type="number" name="peoples" class="form-control" render-value="peoples">-->
            <label>联系方式:</label>
            <input type="text" name="tel" class="form-control">

            <label>目的地:</label>
            <select class="form-control" id="regionSelect" name="region.id" render-value="place.id">

            </select>

        </form>
    </div>

    <hr/>

</div>


</body>

</html>
</body>
</html>